<template>
  <el-dialog title="产品出库" :visible.sync="dialogVisible" width="600px" @close="handleClose">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="出库数" prop="num">
        <el-input v-model="form.num" />
      </el-form-item>
      <el-form-item label="收货人" prop="consignee">
        <el-input v-model="form.consignee" />
      </el-form-item>
      <el-form-item label="备注" prop="note">
        <el-input v-model="form.note" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitHandle">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { outMaterial } from '@/api/materialEnter';
export default {
  data() {
    return {
      row: null,
      form: {
        consignee: '',
        note: '',
        num: '',
        signImage: '',
      },
      rules: {
        num: [{ required: true, message: '请输入出库数', trigger: 'blur' }],
        consignee: [{ required: true, message: '请输入收货人', trigger: 'blur' }],
      },
      dialogVisible: false,
    };
  },
  methods: {
    handleClose() {
      this.$refs.form.resetFields();
      this.row = null;
      this.dialogVisible = false;
    },
    openHandle(row) {
      console.log('row', row);
      this.row = row;
      this.dialogVisible = true;
    },
    submitHandle() {
      this.$refs.form.validate(valid => {
        if (valid) {
          const submitParam = { ...this.form };
          // submitParam.id = this.row.id;
          submitParam.materialId = this.row.materialId;
          submitParam.isIn = 2;
          outMaterial(submitParam).then(res => {
            const { success } = res;
            if(success) {
              this.$message.success('出库成功');
              this.$emit('submit');
              this.handleClose();
            } else {
              this.$message.error('出库失败');
            }
          });
        }
      });
    },
  },
};
</script>
